package com.kitty.game.equip.handler;

import com.kitty.game.role.model.Role;
import com.kitty.game.equip.model.RoleEquip;
import com.kitty.game.equip.model.RoleEquipField;
import com.kitty.game.enter.RespGeneralNotify;
import com.kitty.game.utils.NotifyModules;
import com.kitty.mina.message.MessagePusher;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import com.kitty.game.equip.handler.UpgradeHandler;

@Component("EquipResonanceReplace")
public class EquipResonanceReplaceHandler extends UpgradeHandler{
    private static final String SUCCESS_MESSAGE = "共鸣属性替换成功。";

    private static final List<Integer> FIELD = Collections.singletonList(6914);
    private static final List<Integer> PREPFIELD = Collections.singletonList(7170);

    @Override
    public String doUpgrade(Role role, Object... params) {
        return null;
    }

    @Override
    public String acceptUpgrade(Role role, int upgradePos, String param) {
        RoleEquip roleEquip = equipService.getRoleEquipByPos(role, upgradePos);
        if(roleEquip==null){
            return "请放入正确的装备。";
        }
        AtomicInteger i = new AtomicInteger();
        PREPFIELD.forEach(preField -> {
            int p = i.getAndIncrement();
            RoleEquipField roleEquipField = roleEquip.getFields().get(preField.shortValue());
            roleEquipField.setType(FIELD.get(p).shortValue());
            roleEquip.getFields().remove(preField.shortValue());
            roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        });
        equipService.countPerfect(roleEquip);
        refreshRoleEquip(role, roleEquip);

        RespGeneralNotify respGeneralNotify = new RespGeneralNotify();
        respGeneralNotify.setValue(roleEquip.getId() + "");
        respGeneralNotify.setNotify((short) NotifyModules.NOTIFY_EQUIP_REFINE_OK);//炼化成功
        MessagePusher.pushMessage(role, respGeneralNotify);
        return SUCCESS_MESSAGE;
    }

    @Override
    public String checkResource(Object... objects) {
        return null;
    }

    @Override
    public int needCash(short level, int pos) {
        return 0;
    }

    @Override
    public String getUpdateTypeStr() {
        return null;
    }
}
